package gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTextField;

import javax.swing.WindowConstants;

import model.basics.Instructor;
import model.search.System;

import org.jdesktop.application.Application;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CreateWind extends javax.swing.JFrame {
	private JTextField nameField;
	private JLabel nameLabel;
	private JButton okButton;
	private model.search.System sistem;
	private Instructor instructor;
	private JList instList;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JButton cancelButton;
	private JLabel jLabel1;
	private JTextField mailField;
	private JTextField phoneField;
	private JTextField idField;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				CreateWind inst = new CreateWind();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public CreateWind() {
		super();
		initGUI();
	}
	
	public CreateWind(model.search.System aSistem, JList instructors) {
		super();
		this.sistem = aSistem;
		this.instList = instructors;
		this.instructor = new Instructor();
		this.setVisible(true);
		initGUI();
	}

	private void initGUI() {
		this.setTitle("Create a new instructor");
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				nameField = new JTextField();
				getContentPane().add(nameField);
				nameField.setBounds(192, 37, 113, 21);
			}
			{
				okButton = new JButton();
				getContentPane().add(okButton);
				okButton.setBounds(192, 241, 83, 21);
				okButton.setName("okButton");
				okButton.addActionListener(new AddInstructor(instructor, this));
			}
			{
				nameLabel = new JLabel();
				getContentPane().add(nameLabel);
				nameLabel.setBounds(59, 40, 90, 14);
				nameLabel.setName("nameLabel");
			}
			{
				idField = new JTextField();
				getContentPane().add(idField);
				idField.setBounds(192, 82, 113, 21);
				idField.setName("idField");
			}
			{
				phoneField = new JTextField();
				getContentPane().add(phoneField);
				phoneField.setBounds(192, 127, 113, 21);
			}
			{
				mailField = new JTextField();
				getContentPane().add(mailField);
				mailField.setBounds(192, 172, 113, 21);
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setBounds(59, 85, 90, 14);
				jLabel1.setName("jLabel1");
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setBounds(59, 130, 121, 14);
				jLabel2.setName("jLabel2");
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setBounds(59, 175, 102, 14);
				jLabel3.setName("jLabel3");
			}
			{
				cancelButton = new JButton();
				getContentPane().add(cancelButton);
				cancelButton.setBounds(292, 241, 83, 21);
				cancelButton.setName("cancelButton");
				cancelButton.addActionListener(new Cancel(this));
			}
			pack();
			setSize(400, 300);
			Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(getContentPane());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public class AddInstructor implements ActionListener{
		
		private Instructor ins;
		private JFrame fram;
		public AddInstructor(Instructor i, JFrame j){
			this.ins = i;
			this.fram = j;
		}
		
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			sistem.getInstructorsList().add(new Instructor(nameField.getText(), Integer.parseInt((idField.getText())), (Integer.parseInt(phoneField.getText())),mailField.getText(), "sdfsd"));
			instList.setListData((Vector<Instructor>)sistem.getInstructorsList());
			fram.dispose();
		}
		
		
	}
	
	public class Cancel implements ActionListener{
		private JFrame fra;
		
		public Cancel(JFrame j){
			this.fra= j;
		}

		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			fra.dispose();
		}
		
	}

}
